#ifndef ROOM_MANAGER_H
#define ROOM_MANAGER_H

#include <string>
#include <unordered_map>
#include <vector>
#include <set>

class Room {
public:
    std::string name;
    std::string password;
    std::set<int> members;
    
    Room() = default;
    Room(const std::string& _name, const std::string& pwd = "")
    :name(_name), password(pwd) {}

    void add(int fd) { members.insert(fd); }
    void remove(int fd) { members.erase(fd); }
    bool has(int fd) const { return members.count(fd) > 0; }
};

class RoomManager {
private:
    std::unordered_map<std::string, Room> rooms;
public:
    RoomManager();

    bool join(int fd, const std::string& room_name, const std::string& pwd, std::string& err);
    void leave(int fd);
    std::string get_user_room(int fd) const;
    std::vector<int> get_members(const std::string& room_name) const;
    std::unordered_map<std::string, std::set<int>> get_all_rooms() const;
};

#endif

